home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / cutp.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  3KB  |  122 lines

  1.  
  2.     /***********************************************
  3.     *
  4.     *       file d:\cips\cutp.c
  5.     *
  6.     *       Functions: This file contains
  7.     *          cut_image_piece
  8.     *          paste_image_piece
  9.     *          check_cut_and_paste_limits
  10.     *
  11.     *       Purpose:
  12.     *          These functions cut pieces out
  13.     *          of images and paste them back into
  14.     *          images.
  15.     *
  16.     *       External Calls:
  17.     *          wtiff.c - does_not_exist
  18.     *                    round_off_image_size
  19.     *                    create_file_if_needed
  20.     *                    write_array_into_tiff_image
  21.     *          tiff.c - read_tiff_header
  22.     *          rtiff.c - read_tiff_image
  23.     *
  24.     *
  25.     *       Modifications:
  26.     *          3 April 1992 - created
  27.     *
  28.     *************************************************/
  29.  
  30. #include "cips.h"
  31.  
  32.      /*******************************************
  33.      *
  34.      *   cut_image_piece(...
  35.      *
  36.      *   This function cuts out a rectangular
  37.      *   piece of an image.  This rectangle can
  38.      *   be any shape so long as no dimension
  39.      *   is greater than ROWS or COLS.
  40.      *
  41.      *******************************************/
  42.  
  43.  
  44. cut_image_piece(name, the_image, il, ie, ll, le)
  45.    char   name[];
  46.    int    il, ie, ll, le;
  47.    short  the_image[ROWS][COLS];
  48.  
  49. {
  50.    if(does_not_exist(name)){
  51.       printf("\n\ncut_image_piece>> ERROR "
  52.              "image file does not exist %s", name);
  53.       return(-1);
  54.    }  /* ends if does_not_exist */
  55.  
  56.    read_tiff_image(name, the_image, il, ie, ll, le);
  57.  
  58. }  /* ends cut_image_piece */
  59.  
  60.  
  61.  
  62.  
  63.      /*******************************************
  64.      *
  65.      *   paste_image_piece(...
  66.      *
  67.      *   This function pastes a rectangular
  68.      *   piece of an image into another image.
  69.      *   This rectangle can be any shape so long
  70.      *   as no dimension is greater than ROWS or COLS.
  71.      *   The rectangle to be pasted into the image
  72.      *   is described by the il, ie, ll, le
  73.      *   parameters.
  74.      *
  75.      *   You pass is the out_image array just in
  76.      *   case you need to allocate the destination
  77.      *   image.
  78.      *
  79.      *******************************************/
  80.  
  81.  
  82. paste_image_piece(dest_name, source_name, the_image,
  83.                   out_image, il, ie, ll, le)
  84.    char   dest_name[], source_name[];
  85.    int    il, ie, ll, le;
  86.    short  the_image[ROWS][COLS],
  87.           out_image[ROWS][COLS];
  88.  
  89. {
  90.    struct tiff_header_struct image_header;
  91.  
  92.    create_file_if_needed(source_name, dest_name, 
  93.                          out_image);
  94.  
  95.    write_array_into_tiff_image(dest_name, the_image,
  96.                                il, ie, ll, le);
  97.  
  98. }  /* ends paste_image_piece */
  99.  
  100.  
  101.  
  102.      /*******************************************
  103.      *
  104.      *   check_cut_and_paste_limits(...
  105.      *
  106.      *   This function looks at the line and
  107.      *   element parameters and ensures that they
  108.      *   are not bigger than ROWS and COLS.  If
  109.      *   they are bigger, the last element or
  110.      *   last line parameters are reduced.
  111.      *
  112.      *******************************************/
  113.  
  114. check_cut_and_paste_limits(il, ie, ll, le)
  115.    int *il, *ie, *ll, *le;
  116. {
  117.    if((*ll - *il) > ROWS)
  118.       *ll = *il + ROWS;
  119.    if((*le - *ie) > COLS)
  120.       *le = *ie + COLS;
  121. }  /* ends check_cut_and_paste_limits */
  122.